package com.yupi.usercenter.controller;

import com.yupi.usercenter.common.BaseResponse;
import com.yupi.usercenter.common.ResultUtils;
import com.yupi.usercenter.model.domain.ChatMessage;
import com.yupi.usercenter.service.ChatMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/chat")
public class ChatController {

    @Resource
    private ChatMessageService chatMessageService;

    /**
     * 私聊的历史记录
     */
    @GetMapping("/history")
    public BaseResponse<List<ChatMessage>> privateChat(Long targetUserId, Integer pageNum, Integer pageSize, HttpServletRequest  request) {
        return ResultUtils.success(chatMessageService.getHistoryMessageList(targetUserId, pageNum, pageSize,request));
    }

    /**
     * 最新的一条聊天消息
     */
    @GetMapping("/history/list")
    public BaseResponse<ChatMessage> latestMessage(Long targetUserId,HttpServletRequest request) {
        return ResultUtils.success(chatMessageService.getLatestMessage(targetUserId,request));
    }

    /**
     * 群聊
     */
    @RequestMapping("/room")
    public String groupChat() {
        return "room chat";
    }

    /**
     * 世界聊天
     */
    @RequestMapping("/world")
    public String worldChat() {
        return "world chat";
    }
}
